import request from "../../network/request"
export default {
        getUserInfo(context,args){
             return  new Promise((resolve,reject)=>{
                request({
                    url:'/admin/login',
                    method:'post',
                    data:{
                        phone:args.account,
                        password:args.password
                    }
                }).then(async res=>{
                    if(res.data.code!=200) {
                        resolve('err')
                        return
                    }
                    var user= res.data.data.info              
                     window.sessionStorage.setItem('user',JSON.stringify(user))
                     context.commit('setUserToken',user)  
                     await context.dispatch('getNavTreeData')   //获取左侧菜单数据                                  
                     resolve(res)
                },err=>{
                    resolve('err')
                })
            })
        },
        getNavTreeData(context){ //获取侧边导航栏菜单
            return new Promise((resolve,reject)=>{
                request({
                    url:'/menu/getAuth',
                    method:'get',
                }).then(res=>{
                   var navTreeData=res.data.data.tree
                   window.sessionStorage.setItem('navTreeData',JSON.stringify(navTreeData))
                  
                   context.commit('setNavTreeData',navTreeData)            
                    resolve(res)
                },err=>{
                    resolve('err')
                })
            })
            
        }
}